package top.humbleyuan.double_pointer;

import top.humbleyuan.datastructure.linkedlist.LinkNode;

/**
 * @Author HumbleYuan
 * @Date 2020/5/18 22:11
 * @Des 分隔链表
 */
public class LeetCode_86 {
    public static void main(String[] args) {
        /**
         * 数据准备
         */
        LinkNode head = new LinkNode(1);
        int[] vals = {4,3,2,5,2};
        head = LinkNode.formLink(head,vals);

        int x = 3;

        LinkNode left = new LinkNode(0);
        LinkNode right = new LinkNode(0);


        LinkNode leftTemp = left;
        LinkNode rightTemp = right;


        while (head != null) {
            if(head.val < x) {
                leftTemp.next = head;
                leftTemp = leftTemp.next;
            } else if(head.val >= x) {
                rightTemp.next = head;
                rightTemp = rightTemp.next;
            }

            head = head.next;
        }
        rightTemp.next = null;
        leftTemp.next = right.next;


        LinkNode.headToString(left.next);
    }
}
